package cn.iocoder.yudao.hires.controller.admin;

import cn.iocoder.yudao.hires.vo.ResumeEducationPageReqVO;
import cn.iocoder.yudao.hires.vo.ResumeEducationRespVO;
import cn.iocoder.yudao.hires.vo.ResumeEducationSaveReqVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;



import javax.validation.Valid;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import javax.servlet.http.HttpServletResponse;
import cn.iocoder.yudao.hires.entity.ResumeEducationDO;
import cn.iocoder.yudao.hires.service.ResumeEducationService;

@Tag(name = "管理后台 - 简历-教育经历")
@RestController
@RequestMapping("/resume/education")
@Validated
public class ResumeEducationController {

    @Resource
    private ResumeEducationService educationService;

    @PostMapping("/create")
    @Operation(summary = "创建简历-教育经历")
    //@PreAuthorize("@ss.hasPermission('resume:education:create')")
    public CommonResult<Integer> createEducation(@Valid @RequestBody ResumeEducationSaveReqVO createReqVO) {
        return success(educationService.createEducation(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新简历-教育经历")
    //@PreAuthorize("@ss.hasPermission('resume:education:update')")
    public CommonResult<Boolean> updateEducation(@Valid @RequestBody ResumeEducationSaveReqVO updateReqVO) {
        educationService.updateEducation(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除简历-教育经历")
    @Parameter(name = "id", description = "编号", required = true)
    //@PreAuthorize("@ss.hasPermission('resume:education:delete')")
    public CommonResult<Boolean> deleteEducation(@RequestParam("id") Integer id) {
        educationService.deleteEducation(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得简历-教育经历")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    //@PreAuthorize("@ss.hasPermission('resume:education:query')")
    public CommonResult<ResumeEducationRespVO> getEducation(@RequestParam("id") Integer id) {
        ResumeEducationDO education = educationService.getEducation(id);
        return success(BeanUtils.toBean(education, ResumeEducationRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得简历-教育经历分页")
    //@PreAuthorize("@ss.hasPermission('resume:education:query')")
    public CommonResult<PageResult<ResumeEducationRespVO>> getEducationPage(@Valid ResumeEducationPageReqVO pageReqVO) {
        PageResult<ResumeEducationDO> pageResult = educationService.getEducationPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ResumeEducationRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出简历-教育经历 Excel")
    //@PreAuthorize("@ss.hasPermission('resume:education:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportEducationExcel(@Valid ResumeEducationPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ResumeEducationDO> list = educationService.getEducationPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "简历-教育经历.xls", "数据", ResumeEducationRespVO.class,
                        BeanUtils.toBean(list, ResumeEducationRespVO.class));
    }

}